package cn.czk.demo;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;

public class MemoryChatDemo {

    public static void main(String[] args) {
        MessageWindowChatMemory chatMemory = MessageWindowChatMemory.builder()
                .maxMessages(10)
                .build();

        OpenAiChatModel model = OpenAiChatModel.builder()
                .apiKey("53e452feb1164ec8a6c9cd9112a37d60.xTOwz9t4NIZuYTYb")
                .modelName("glm-4")
                .baseUrl("https://open.bigmodel.cn/api/paas/v4/")
                .temperature(0.95)
                .build();

        chatMemory.add(UserMessage.userMessage("你好，我是⼩明，你是我最好的兄弟，叫做阿强"));
        AiMessage answer1 = model.generate(chatMemory.messages()).content();
        System.out.println(answer1.text());
        chatMemory.add(answer1);

        chatMemory.add(UserMessage.userMessage("小明最好的朋友是谁？"));

        AiMessage answer2 = model.generate(chatMemory.messages()).content();
        System.out.println(answer2.text());


    }

}
